<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.utils.SiteHelper" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.admin.withdraw.vo.BindVo" %>
<%@ page import="com.qipay.admin.withdraw.vo.WithdrawVo" %>
<%@ page import="com.qipay.baas.model.CpAccount" %>
<%@ page import="com.qipay.configuration.config.ConfigurationEnum" %>
<%@ page import="com.qipay.user.entity.UserLevel" %>
<%@ page import="org.apache.commons.collections.CollectionUtils" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.qipay.baas.model.Peizhi" %>
<!doctype html>
<html>
<head>
    <jsp:include page="head.jsp"></jsp:include>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/bootstrapValidator.min.css">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <div class="content-wrapper">
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box box-info">
                        <%
                            UserLevel userLevel = (UserLevel) request.getAttribute("level");
                        %>
                        <div class="box">
                            <div class="box-header">
                                <h3 class="box-title">公告配置</h3>
                            </div>
                            <%
                                Peizhi peizhi = (Peizhi) request.getAttribute("peizhi");
                            %>
                            <div class="box-body">
                                <form class="form-horizontal" action="/notice/save" method="POST" id="applyForm">
                                    <input type="hidden" name = "id" value="<%=peizhi.getId()%>"/>
                                    <div class="form-group col-sm-10">
                                        <textarea name="content" style="height: 500px;width: 100%;border:1px solid #dcdcdc ;resize: none" placeholder="请输入公告内容"><%=peizhi.getContent()%></textarea>
                                    </div>
                                    <div style="clear: both"></div>
                                    <div >
                                        <button type="submit" class="button back-green" id="btnSubmit" style="position:relative;bottom: 5px;">提交</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    <jsp:include page="foot.jsp"></jsp:include>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/icheck.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/bootstrapValidator.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/business/withdraw_apply.js?v=<%= request.getAttribute("StaticVersion") %>"></script>
<script type="text/javascript">

    $(function () {

        // init.args
        var operation = $("#operation_tab li.active").attr("key");
        var password = $("#password").val();
        var min = Number($("#minVal").val());
        var max = Number($("#maxVal").val());
        console.log(min);
        console.log($("#maxVal").val() + "= " + max);
        var start = $("#start").val();
        var end = $("#end").val();
        var code = "";
        type = $(".tab-content div.active .type").find("option:selected").attr("type");

        // init.fill
        $("#type").val(type);
        $("#operation").val(operation);
        $("#operationName").val($("#operation_tab li.active a").text());
        initAmount();

        // init.validator
        $('#applyForm').bootstrapValidator({
            framework: 'bootstrap',
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                operationName: {
                    validators: {
                        notEmpty: {
                            message: '操作类型不能为空'
                        }, callback: {
                            message: '提现申请时间为 ' + start + '-' + end + ',请至有效时间后刷新界面重试',
                            callback: function (value, validator) {
                                return checkTime();
                            }
                        }
                    }
                },
                amount: {
                    validators: {
                        notEmpty: {
                            message: '操作金额不能为空'
                        },
                        callback: {
                            message: '操作金额不足',
                            callback: function (value, validator) {

                                var available = Number($("#availableVal").val());
                                var advance = Number($("#advanceVal").val());
                                return value <= (0 == type ? available : advance);
                            }
                        },
                        between: {
                            min: min,
                            max: max,
                            message: '操作金额范围为' + min + '到' + max
                        }
                    }
                },
                fee: {
                    validators: {
                        notEmpty: {
                            message: '扣费金额不能为空'
                        }
                    }
                },
                actualAmount: {
                    validators: {
                        notEmpty: {
                            message: '实际到账金额不能为空'
                        }
                    }
                },
                cardBank: {
                    validators: {
                        notEmpty: {
                            message: '银行名称不能为空'
                        }
                    }
                },
                cardSubBank: {
                    validators: {
                        notEmpty: {
                            message: '支行名称不能为空'
                        }
                    }
                },
                cardNo: {
                    validators: {
                        notEmpty: {
                            message: '卡号不能为空'
                        }, stringLength: {
                            min: 16,
                            max: 19,
                            message: '银行卡位数有误'
                        },
                    }
                },
                name: {
                    validators: {
                        notEmpty: {
                            message: '姓名不能为空'
                        }
                    }
                },
                mobile: {
                    validators: {
                        notEmpty: {
                            message: '银行预留手机号不能为空'
                        },
                        regexp: {
                            regexp: /^[0-9]{11}$/,
                            message: '手机号位数有误'
                        }
                    }
                },
                validCode: {
                    validators: {
                        notEmpty: {
                            message: '手机校验码不能为空'
                        },
                        callback: {
                            message: '手机校验码错误',
                            callback: function (value, validator) {
                                return code == value;
                            }
                        },
                    }
                },
                withdrawPassword: {
                    validators: {
                        notEmpty: {
                            message: '提现密码不能为空'
                        },
                        callback: {
                            message: '提现密码错误',
                            callback: function (value, validator) {
                                return password == value;
                            }
                        },
                    },
                    regexp: {
                        regexp: /^[0-9]{6}$/,
                        message: '提现密码位数有误'
                    }
                },
            }
        });

        // sms
        $("#sendValid").click(function () {

            // disable
            var limit = 60;
            $("#sendValid").attr("disabled", true);
            var timer = setInterval(function () {
                if (--limit != 0) {
                    console.log(limit)
                    $("#sendValid").text(limit + "秒后重发");
                } else {
                    console.log("60s pass")
                    $("#sendValid").text("发送校验码");
                    $("#sendValid").attr("disabled", false);
                    clearInterval(timer);
                }
            }, 1000);

            // request
            $.get("/withdraw/valid", function (data) {
                if (null != data && data.code == 200) {
                    code = data.data;
                } else {
                    console.log("get fail")
                    clearInterval(timer);
                    $("#sendValid").attr("disabled", false);
                    $("#sendValid").text("发送校验码");
                    alert("失败:" + data.msg);
                }
            }).fail(function () {
                console.log("get request fail")
                clearInterval(timer);
                $("#sendValid").attr("disabled", false);
                $("#sendValid").text("发送校验码");
            });
        });
    });


    function checkTime() {

        // curTime
        var date = new Date();
        var start = $("#start").val();
        var end = $("#end").val();
        var curTime = date.getHours() * 100 + date.getMinutes();
        var startLimit = parseFloat(start.replace(":", ""));
        var endLimit = parseFloat(end.replace(":", ""));

        // check
        return curTime > startLimit && curTime < endLimit
    }
</script>
</body>
</html>

